package com.rookie.tool.module.util.trigger.component;

import java.io.*;

/**
 * @author rookie
 */
public class CloneUtils {

	@SuppressWarnings("unchecked")
	public static <T extends Serializable> T clone(T obj){
		
		T clonedObj = null;
		try {
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
			oos.writeObject(obj);
			oos.close();
			
			ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
			ObjectInputStream ois = new ObjectInputStream(byteArrayInputStream);
			clonedObj = (T) ois.readObject();
			ois.close();
			
		}catch (Exception e){
			e.printStackTrace();
		}
		
		return clonedObj;
	}
}